// components/vote-item/vote-item.js
// import dayjs from 'dayjs';
import { COS_HOST } from '../../utils/httpServer';

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    voteId: Number,
    daysLeft: Number,
    userCount: Number,
    title: String,
    imgUrl: String,
    state: Number,
    isHistory: Boolean,
  },

  observers: {
    daysLeft(value) {
      let leftStr = `${value}天后结束`;
      if (value < 0) {
        leftStr = '已结束';
      }
      this.setData({
        leftStr,
      });
    },
    // hot(value) {
    //   let hotStr = value + '';
    //   if (value >= 100000) {
    //     hotStr = '10w+';
    //   }
    //   this.setData({
    //     hotStr,
    //   });
    // },
  },

  /**
   * 组件的初始数据
   */
  data: {
    leftStr: '',
    // hotStr: '',
    COS_HOST,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleTap(e) {
      if (this.properties.state == 1) {
        wx.navigateTo({
          url: `/pages/vote-detail/vote-detail?voteId=${this.data.voteId}`,
        });
      } else {
        wx.navigateTo({
          url: `/pages/vote-result/vote-result?voteId=${this.data.voteId}`,
        })
      }
    },
  }
})